<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
define('NOSESSION',true);
require_once '../../core/core.php';
define('NO_ERROR_RETURN',true);
define('WXAPI',true);
set_exi(function($message,$type,$action,$url){
	ob_clean();
	exit('');
});
if($_AR['close']){
	exi('站点已关闭','error');
}
$id = intval($_RQ['id']);
if(!$id){
	exi('error1','error');
}
$wechat=pdo_get('jy_apioauth_wechat',array('id'=>$id));
$token =$wechat['token'];
$signkey = array($token, $_GET['timestamp'], $_GET['nonce']);
sort($signkey, SORT_STRING);
$signString = implode($signkey);
$signString = sha1($signString);
if($signString != $_GET['signature']){
	exi('error signature');
}
if(strtolower($_SERVER['REQUEST_METHOD']) == 'get') {
	ob_clean();
	exit(htmlspecialchars($_GET['echostr']));
}
if(strtolower($_SERVER['REQUEST_METHOD']) != 'post') {
	exit('error8');
}
$xml_data=file_get_contents('php://input');
if($xml_data){
	$headers = array('Content-Type' => 'text/xml');
	$wechats=json_decode($wechat['wechats'],true);
	paixu($wechats,'paixu','desc');
	foreach($wechats as $wv){
		if($wv['url']){
			cfc('http')->ihttp_request($wv['url'], $xml_data, $headers);
		}
	}
}
exi('success');